<?
$locale= Zend_Registry::get('Zend_Locale');

$request= Zend_Controller_Front::getInstance()->getRequest();

switch($locale)
{
    case 'en_GB':
        $format='yy-mm-dd';
        break;
    default:
        $format='dd-mm-yy';
}


$f=new Zend_Date();
$f->setDay(4);

for($i=1;$i<=12;$i++)
{
    $mesNames[$i]=$f->setMonth($i)->get('MMMM');
    $mesNamesShort[$i]=$f->get('MMM');
}
$monthNames=" ['".implode("','",$mesNames)."']";
$monthNamesShort=" ['".implode("','",$mesNamesShort)."']";

$f->set(0,Zend_Date::WEEKDAY_DIGIT);
for($i=0;$i<=6;$i++)
{
    $f->set($i,Zend_Date::WEEKDAY_DIGIT);
    $diaNames[$i]=      $f->get('EEEE');
    $diaNamesShort[$i]= $f->get('EEE');
    $diaNamesMin[$i]= $f->get('EE');
}
$dayNames=" ['".implode("','",$diaNames)."']";
$dayNamesShort=" ['".implode("','",$diaNamesShort)."']";
$dayNamesMin=" ['".implode("','",$diaNamesMin)."']";
?>


// Define your global object  
var sgitObject = {};





var i18n_meses = new Array();
<?foreach($mesNames as $k => $v):?>
i18n_meses['<?=$v?>'] = '<?=sprintf("%02s",$k)?>';i18n_meses['<?=$mesNamesShort[$k]?>'] = '<?=sprintf("%02s",$k)?>';
<?endforeach?>


jQuery(function($){
$.datepicker.regional['default'] = {closeText: '<?php echo $this->translate('Cerrar');?>',prevText: '&#x3c;<?php echo $this->translate('Ant');?>',nextText: '<?php echo $this->translate('Sig');?>&#x3e;',currentText: '<?php echo $this->translate('Hoy');?>',monthNames: <?=$monthNames ?>,monthNamesShort: <?=$monthNamesShort?>,dayNames: <?=$dayNames?>,dayNamesShort: <?=$dayNamesShort?>,dayNamesMin: <?=$dayNamesMin?>,weekHeader: '<?php echo $this->translate('Sm');?>',dateFormat: '<?php echo $format;?>',firstDay: 1,isRTL: false,showMonthAfterYear: false,yearSuffix: ''};
$.datepicker.setDefaults($.datepicker.regional['default']);
});

//localization
my_dictionary = { 
    'Guardar': '<?php echo $this->translate('Guardar');?>',
    'Cancelar': '<?php echo $this->translate('Cancelar');?>',
    '| Render %s seg': '<?php echo $this->translate('| Render %s seg');?>',
    'Información': '<?php echo $this->translate('Información');?>',
    'Cerrar': '<?php echo $this->translate('Cerrar');?>',
    'Borrar': '<?php echo $this->translate('Borrar');?>',
    'enero':'<?php echo $mesNames[1]?>','ene':'<?php echo $mesNamesShort[1]?>','febrero':'<?php echo $mesNames[2]?>','feb':'<?php echo $mesNamesShort[2]?>','marzo':'<?php echo $mesNames[3]?>','mar':'<?php echo $mesNamesShort[3]?>','abril':'<?php echo $mesNames[4]?>','abr':'<?php echo $mesNamesShort[4]?>','mayo':'<?php echo $mesNames[5]?>','may':'<?php echo $mesNamesShort[5]?>','junio':'<?php echo $mesNames[6]?>','jun':'<?php echo $mesNamesShort[6]?>','julio':'<?php echo $mesNames[7]?>','jul':'<?php echo $mesNamesShort[7]?>','agosto':'<?php echo $mesNames[8]?>','ago':'<?php echo $mesNamesShort[8]?>','septiembre':'<?php echo $mesNames[9]?>','sep':'<?php echo $mesNamesShort[9]?>','octubre':'<?php echo $mesNames[10]?>','oct':'<?php echo $mesNamesShort[10]?>','noviembre':'<?php echo $mesNames[11]?>','nov':'<?php echo $mesNamesShort[11]?>','diciembre':'<?php echo $mesNames[12]?>','dic':'<?php echo $mesNamesShort[12]?>',
}
$.i18n.setDictionary(my_dictionary);





$(document).on('ready',function(){ 

   

    <?if($this->idZona):?>
    $("#layoutdims").on("change", "#change_dc", function(event){
        
        //coge query string y cambia idZona
        loc=location.href;
        zona_actual="/idZona/<?=$this->idZona?>";
        zona_nueva="/idZona/"+this.value;
        path=loc.split(zona_actual).join(zona_nueva);
        //crea un formulario que simula la recarga de la pagina en la nueva zona 
        var form = document.createElement("form");
        form.setAttribute("method", 'POST');
        form.setAttribute("action", path);
    

        <?php foreach($request->getParams() as $k => $v):
            if(in_array($k,array('controller','action','idZona','module','error_handler'))) continue;
        ?>
   	    var hiddenField = document.createElement("input");
   	    hiddenField.setAttribute("type", "hidden");
   	    hiddenField.setAttribute("name", "<?php echo $k?>");
   	    hiddenField.setAttribute("value","<?php echo $v?>");
   	    form.appendChild(hiddenField);
        <?php endforeach;?>
    
        document.body.appendChild(form);
        form.submit();
        
	})
    <?endif?>


    $(document).on("click",'.utildelete', function(e){        
    	e.preventDefault();
    	var url=this.href;
        var tr = $(this).closest('tr');

        var postion=[e.clientX-350,e.clientY];
        
        $( "#dialog-confirm" ).dialog( "option", "position", postion );
        
    	$('#dialog-confirm').dialog({buttons: { 
				"<?php echo $this->translate('Borrar');?>": function() {
					$.post(url,  function(data){
						if(data.status=='ok'){
						    var n = noty({type:'success',timeout:5000,text: 'Borrado con exito'});
              
						    $('#dialog-confirm').dialog("close");  
							tr.hide();
							
						}else if(data.status=='reload'){
						      var n = noty({type:'success',timeout:5000,text: 'Borrado con exito, se esta recargando la pagina para mostrar los cambios'});
						      location.reload();
						}else
						{
						    var n = noty({type:'alert',timeout:10000,text: 'Ha ocurrido algo inesperado'});
						     
							$('#dialog').html(data).dialog("open").dialog({title:''});
							$('#dialog-confirm').dialog("close");
						}
					})
				} ,
				"<?php echo $this->translate('Cancel');?>": function() { $(this).dialog("close"); } 
			}
		})
	    .dialog('open');  
    })
    
    $('.utildelete').css('cursor','pointer')
    .button({
            text: false,
            icons: {
                primary: "ui-icon-trash"
            }
    });
    
    
    //$(".utildelete_old").live("click", function(e){
    $('table').on("click",'.utildelete_old', function(e){          
    	e.preventDefault();
        aux=this.id.split('-');
        id=aux[0]
        file=aux[1]
        idZona=aux[2]
        
       
    	$('#dialog-confirm').dialog({buttons: { 
    			"<?php echo $this->translate('Borrar');?>": function() { 
    				$.post('index.php', {ajax:file, action: 'borrar', id: id,idZona: idZona},  function(data){
    					if(data=='ok'){location.reload();$('#dialog-confirm').dialog("close");}
    					if(data!='ok'){alert(data);$('#dialog-confirm').dialog("close");}
    				})
    			} ,
    			"<?php echo $this->translate('Cancelar');?>": function() { $(this).dialog("close"); } 
    		}
    	})
        .dialog('open');
    })
    
    $('.utildelete_old').css('cursor','pointer')
    .button({
            text: false,
            icons: {
                primary: "ui-icon-trash"
            }
    });
    
    
    
    
    
})
/*
* Zona para incluir js dinamico en funcion de id_zona
*/
<?php if($this->idZona): ?>





<?endif?>


